--[[
   file:upload_access_check.lua
   author:yuan jie
   date:2015-06-17
   description:This lua file is service as user space check when upload
   vesion: v1.0
   modified history:
--]]

local cjson = require "cjson";

-- local res = ngx.location.capture("/index.php/callback/upload/check",{args = ngx.req.get_uri_args()});

 local args_pass = ngx.req.get_uri_args();

 -- args_pass.file_size = ngx.req.get_headers()["Content-Length"] or "not Content-Length header"
 args_pass.x_session_id = ngx.req.get_headers()["x-session-id"] or "not x-session-id header"
 args_pass.x_csrf_token = ngx.req.get_headers()["x-csrf-token"] or "not x-csrf-token header"
 args_pass.x_access_token = ngx.req.get_headers()["x-access-token"] or "not x-access-token header"

 ngx.req.read_body();
 local arg_post = ngx.req.get_post_args();
  args_pass.file_size = tostring( arg_post["file_size"]);
  args_pass.folder_id = tostring(arg_post["folder_id"]);

 local res = ngx.location.capture("/index.php/callback/upload/check",{args = args_pass} );

 local data = cjson.decode(res.body); 

-- if data["error_code"] == 0 then
  -- return
 --end

ngx.header.content_type = "text/plain";

ngx.status=ngx.HTTP_OK;
ngx.say(res.body);

ngx.exit(ngx.HTTP_OK);
